﻿using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Ports;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BF_160
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        { 
            Application.SetCompatibleTextRenderingDefault(false);


            MyGlobal.logFile = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName) + "\\DebugLog\\";

            if (!Directory.Exists(MyGlobal.logFile)) // 如果该文件夹不存在则创建
                Directory.CreateDirectory(MyGlobal.logFile);
            MyGlobal.logFile += DateTime.Now.ToString("yyyy年MM月dd日HH时mm分") + ".log";



            string strAppDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName);
            Ini cIni = new Ini(strAppDir + "\\config.ini");
            MyGlobal.ytPortName= cIni.ReadValue("COM", "YT", "COM1"); 
            List<string> list = new List<string>();
            list.Add(MyGlobal.ytPortName); 

            foreach (var item in list)
            { 
                try
                {
                    SerialPort serialPort = new SerialPort(item);
                    serialPort.PortName = item;
                    serialPort.BaudRate = 9600;
                    serialPort.Open();

                    if (serialPort.IsOpen)
                    {
                        serialPort.Close();
                    }

                }
                catch (Exception ee)
                {
                    MessageBox.Show($"端口[{item}]打开失败,请修改配置文件端口号!\n" + ee.Message);
                    return;
                }

            }
         //   Application.Run(new FrmYT());
             Application.Run(new FrmYDL());
        }
    }
}
